package com.scpii.universal.service.impl;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.scpii.universal.constant.GenericConstants;
import com.scpii.universal.hibernate.dao.BaseDao;
import com.scpii.universal.service.BaseService;
import com.scpii.universal.util.EhCacheManager;

/**
 * universalWeb
 * @author liuhj
 * 2012-7-5下午01:22:02
 * @param <T>
 * @param <PK>
 */
@Service
public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {
	
	private BaseDao<T,PK> baseDao;
	
	protected String getServerUrl() {
		return EhCacheManager.getObject(GenericConstants.SERVER_URL_PREFIX).toString();
	}

	public BaseDao<T, PK> getBaseDao() {
		return baseDao;
	}

	public void setBaseDao(BaseDao<T, PK> baseDao) {
		this.baseDao = baseDao;
	}
	
	@Override
	public void delete(T obj) {
		baseDao.delete(obj);
	}

	@Override
	public void delete(PK id) {
		baseDao.delete(id);
	}

	@Override
	public T get(PK id) {
		return baseDao.get(id);
	}

	@Override
	public T get(String propertyName, Object value) {
		return baseDao.get(propertyName, value);
	}

	@Override
	public List<T> getAll() {
		return baseDao.getAll();
	}

	@Override
	public List<T> getList(String propertyName, Object value) {
		return baseDao.getList(propertyName, value);
	}

	@Override
	public Long getTotalCount() {
		return baseDao.getTotalCount();
	}

	@Override
	public List<T> hqlGetList(String namedHqlQuery, Map<String, Object> argsMap) {
		return baseDao.hqlGetList(namedHqlQuery, argsMap);
	}

	@Override
	public Long hqlGetNums(String namedHqlQuery, Map<String, Object> argsMap) {
		return baseDao.hqlGetNums(namedHqlQuery, argsMap);
	}

	@Override
	public void hqlUpdate(String namedHqlQuery, Map<String, Object> argsMap) {
		baseDao.hqlUpdate(namedHqlQuery, argsMap);
	}

	@Override
	public T load(PK id) {
		return baseDao.load(id);
	}

	@Override
	public PK save(T obj) {
		return baseDao.save(obj);
	}

	@Override
	public List<T> sqlGetList(String sqls, Map<String, Object> argsMap) {
		return baseDao.sqlGetList(sqls, argsMap);
	}

	@Override
	public Long sqlGetNum(String sqls, Map<String, Object> argsMap) {
		return baseDao.sqlGetNum(sqls, argsMap);
	}

	@Override
	public void sqlUpdate(String sqls, Map<String, Object> argsMap) {
		baseDao.sqlUpdate(sqls, argsMap);
	}

	@Override
	public void update(T obj) {
		baseDao.update(obj);
	}
	
	/**
	 * 执行Oracle的SQL函数
	 * @param price
	 * @return
	 * @author 甘建新
	 * 2012-9-21下午02:48:16
	 */
	public Integer executeFunction(int price){
		return 0;
	}
}
